<?php

require_once('nusoap/lib/nusoap.php');
require_once('KLogger.php');
//require_once('configuration.php');

class BomCommon{
	private static $config_db_server = array('host'=>'localhost', 'username'=>'root', 'password'=>'1234', 'dbname'=>'chulapack_cu');
	//private static $config_db_server = array('host'=>'localhost', 'username'=>'chulapack', 'password'=>'2APRXFCBQ', 'dbname'=>'chulapack_cu');
	private static $private_key = 'E2E6C938';

	public static function decodeParams($str=""){
		return json_decode($str);
	}
	public static function openDBConnection(){
		$link=mysql_pconnect(self::$config_db_server['host'],self::$config_db_server['username'],self::$config_db_server['password']);
		mysql_select_db(self::$config_db_server['dbname']);
		mysql_query("SET character_set_results=utf8");
		mysql_query("SET character_set_client=utf8");
		mysql_query("SET character_set_connection=utf8");
		return $link;
	}
	public static function closeDBConnection($link){
		mysql_close($link);
	}
	public static function excuteDB($link, $strSQL){
		return mysql_query($strSQL, $link);
	}
	public static function mysql_ToArray($result){
		$arr_result = array();
		while($row=mysql_fetch_assoc($result)){
			array_push($arr_result, $row);
		}
		return $arr_result;
	}
	public static function checkPrivateKey($input){
		return (self::$private_key == $input);
	}
}

class Logger{
	private $log;
	public static $DEBUG = 1;
	public static $INFO = 2;
	public static $ERROR = 3;
	public function __construct(){
		$this->log = new KLogger ( "log/log.txt" , KLogger::DEBUG );
	}
	public function log($line, $type=1){
		$bt =  debug_backtrace();
		$line="[".basename($bt[0]['file'])."->".$bt[1]['function'].":".$bt[0]['line']."]: ".$line;
		
		if($type == self::$DEBUG){
			$this->log->LogDebug($line);
		}elseif($type == self::$INFO){
			$this->log->LogInfo($line);
		}elseif($type == self::$ERROR){
			$this->log->LogError($line);
		}else{
			$this->log->LogDebug($line);
		}
		
	}
}

?>